package com.zhu.controller.system;

import com.zhu.pojo.Dept;
import com.zhu.query.DeptQuery;
import com.zhu.service.IDeptService;
import com.zhu.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaozhu
 * @since 2022-08-24
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    @RequestMapping("/all")
    public List<DeptVo> getDept(DeptQuery deptQuery){
        return deptService.getDept(deptQuery);
    }

    /*
        根据id查找指定部门信息
     */
    @RequestMapping("/detail")
    public Dept getDeptById(@RequestParam("did") Integer did){
        return deptService.getById(did);
    }

    /*
        添加或修改部门信息
     */
    @PostMapping("/action")
    public String deptAction(@RequestBody Dept dept){
        if(dept.getDid()!=null){
            deptService.updateById(dept);
        }else{
            deptService.save(dept);
        }
        return "ok";
    }

    /*
        删除部门信息
     */
    @PostMapping("/del")
    public String deptDel(@RequestBody List<Long> idList){
        deptService.removeTree(idList);
        return "ok";
    }

}
